#include "logindialog.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include <QtDebug>
#include <QCoreApplication>


/*
 注意！！！！！！！！！！！！
 如果出现这个错误:          D:\qt_code\maindlg_dialogismainwindow\logindialog.cpp:-1: error: undefined reference to `vtable for LoginDialog'
    那就说明    这个项目的起始文件是咱们自己的，咱们自己编写的项目是不会自动生成MinGW文件夹里面debug文件夹里面的moc文件的，所以会报错

    解决办法：
            1.手动删除添加的类的cpp和h文件，注意不要勾上下面的彻底删除文件              注意！！！！ 一定要把下面的勾去掉，不然白写了，奥,,,,,，对，还有回收站，嗯..........
            2.重新添加现有文件，把删除的文件再添加回来

     完事，解决。


 */




LoginDialog::LoginDialog()
{
    username_lab = new QLabel("用户名:");
    username = new QLineEdit;
    password_lab = new QLabel("密码  :");
    password = new QLineEdit;
    QPushButton* loginBtn = new QPushButton("login");
    QPushButton* cancelBtn = new QPushButton("cancel");

    password->setEchoMode(QLineEdit::Password);            //设置输出模式:密码模式


    //布局：
    QHBoxLayout* hLayout1 = new QHBoxLayout;
    hLayout1->addWidget(username_lab);
    hLayout1->addWidget(username);

    QHBoxLayout* hLayout2 = new QHBoxLayout;
    hLayout2->addWidget(password_lab);
    hLayout2->addWidget(password);

    QHBoxLayout* hLayout3  = new QHBoxLayout;
    hLayout3->addWidget(loginBtn);
    hLayout3->addStretch();             //添加弹簧
    hLayout3->addWidget(cancelBtn);


    QVBoxLayout* mainLayout = new QVBoxLayout(this);
    mainLayout->addLayout(hLayout1);
    mainLayout->addLayout(hLayout2);
    mainLayout->addLayout(hLayout3);


    connect(loginBtn,SIGNAL(clicked(bool)),this,SLOT(onLoginBtnSlot()));
    connect(cancelBtn,SIGNAL(clicked(bool)),this,SLOT(onCancelBtnSlot()));

//    connect(loginBtn, &QPushButton::clicked, this, &LoginDialog::onLoginBtnSlot);
//    connect(cancelBtn, &QPushButton::clicked, this, &LoginDialog::onCancelBtnSlot);
}

void LoginDialog::onLoginBtnSlot()
{
    qDebug()<<"login";
    if(username->text() == "lifei")
        if(password->text() == "1234")
            qDebug()<<"yes";
}

void LoginDialog::onCancelBtnSlot()
{
    qDebug()<<"cancel";
    QCoreApplication::quit();


}

void LoginDialog::closeEvent(QCloseEvent *ev)
{
    QCoreApplication::quit();
    ev->accept();
}
